<form class="layui-form" method="post">
    <div class="layui-form-item" style="padding-top: 2%">
        <label class="layui-form-label">主机商：</label>
        <div class="layui-input-inline">
            <if condition="$date['ser_id'] neq null">
                <span id="typehost" style="padding: 9px 0px; display: block" <volist name=":C('ServerName')"  id="plats"> <if condition="$plats eq $date['ser_name']">data_id="{:C('ServerProvider')[$key]['val']}"</if>
            </volist>>{$date['ser_name']}</span>
              <else/>
            <select name="types" lay-verify="required" lay-filter="serverstype">
                <option value=""></option>
                <volist name=":C('ServerProvider')"  id="plats">
                    <option value="{$plats['val']}" <if condition="!$plats['is_display']">disabled</if> >{$key}</option>
                </volist>
            </select>
            </if>
        </div>
    </div>
    <div class="layui-form-item"  id="url">
        <label class="layui-form-label">API标示：</label>
        <div class="layui-input-block">
            <input type="text" name="url" lay-verify="required|url" maxlength="40" placeholder=""value="{$date.ser_url}" autocomplete="off" class="layui-input layui-input80">
        </div>
    </div>
    <div class="layui-form-item" id="key">
        <label class="layui-form-label">APIKey：</label>
        <div class="layui-input-block">
            <input type="text" name="key" lay-verify="required" maxlength="40" minlength="31" placeholder=""value="{$date.ser_key}" autocomplete="off"class="layui-input layui-input80">
        </div>
    </div>
    <div class="layui-form-item" id="secret">
        <label class="layui-form-label">APISecret：</label>
        <div class="layui-input-block">
            <input type="text" name="secret" lay-verify="required" maxlength="40" minlength="31" placeholder=""value="{$date.ser_secret}" autocomplete="off"  class="layui-input layui-input80">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="sitesub">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script>
        form.render();
        form.on('select(serverstype)', function(data){
            $('#url input').val('');
            $('#key input').val('');
            $('#secret input').val('');
            type(data.value);
        });
        function type(value){
            if(value == 1){
                $('#url .layui-form-label').html('主机API：');
                $('#url input').attr('lay-verify','required|url');
                $('#key .layui-form-label').html('APIKey：');
                $('#secret .layui-form-label').html('APISecret：');
            }else if(value == 2){
                $('#url .layui-form-label').html('APPID：');
                $('#url input').attr('lay-verify','required');
                $('#key .layui-form-label').html('SecretId：');
                $('#secret .layui-form-label').html('SecretKey：');
            }else if(value == 4){
                $('#url .layui-form-label').html('创建时间：');
                $('#url input').attr('lay-verify','required');
                $('#key .layui-form-label').html('KeyID：');
                $('#secret .layui-form-label').html('KeySecret：');
            }else{
                $('#url .layui-form-label').html('APPID：');
                $('#url input').attr('lay-verify','required');
                $('#key .layui-form-label').html('SecretId：');
                $('#secret .layui-form-label').html('SecretKey：');
            }
        }
        form.on('submit(sitesub)', function(data){
            var userInfo = data.field;
            var url = "__SELF__";
            var loadahsde=layer.load(1, {shade: [0.8, '#393D49'], time: 100000})
            $.post(url,userInfo,function(data){
                layer.close(loadahsde);
                if(data.code == '4001'){
                    layer.msg(data.msg,{icon: 5});
                    return;
                }else if(data.code == '101'){
                    layer.msg(data.msg, {
                        icon: 6,
                        time: 2000
                    }, function(){
                        location.reload();
                    });
                }else{
                    layer.msg("数据错误",{icon: 5});
                    return;
                }
            });

            return false;
        });

</script>
<if condition="!empty($date['ser_name'])">
    <script>
        type($('#typehost').attr('data_id'));
    </script>
</if>